package io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Test1 {
    public static void main(String[] args) {
        String path="D:\\javacode\\javacode\\J2025_2_5\\hello.txt";

        File file=new File(path);
        BufferedWriter bufferedWriter=null;
        try {
            file.createNewFile();//创建
            bufferedWriter = new BufferedWriter(new FileWriter(path));
            String str="这是一个示例";
            bufferedWriter.write(str);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(bufferedWriter!=null){
                try {
                    bufferedWriter.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
